import axios from '@/utils/request'
import qs from 'qs'
import store from '@/store'

/**
 * 读取文章的列表
 * @param {Object} options
 */
const getList = (options) => {
  return axios.get('/public/lists?' + qs.stringify(options))
}

// 温馨提醒
const getTips = () => {
  return axios.get('/public/tips')
}

// 友情链接
const getLinks = () => {
  return axios.get('/public/links')
}
// 本周热议
const getTop = () => {
  return axios.get('/public/top')
}

// 图片上传图片
const uploadImg = (data) => axios.post('/content/upload', data)

// 发帖子
const addPost = (data) => axios.post('/content/add', { ...data })

// 获取文章详情
const getDetail = (tid) => {
  const token = store.state.token
  let headers = {}
  if (token !== '') {
    headers = {
      headers: {
        Authorization: 'Bearer ' + store.state.token
      }
    }
  }
  return axios.get('/public/content/detail?tid=' + tid, headers)
}

export {
  getList, getTips, getTop, getLinks, uploadImg, addPost, getDetail
}
